﻿namespace iTool.Common.Options
{
    public class AdoNetOptions
    {
        private string _connection { get; }
        public AdoNetOptions() { }
        public AdoNetOptions(string connection)
        {
            this._connection = connection;
        }

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string DataSource { get; set; }

        /// <summary>
        /// 用户登录名
        /// </summary>
        public string UID { get; set; }

        /// <summary>
        /// 登录密码
        /// </summary>
        public string PWD { get; set; }

        /// <summary>
        /// 数据库名称，默认：[iTool.ClusterComponent]；
        /// 如果数据库不存在会在运行时创建
        /// </summary>
        public string DatabaseName { get; set; } = "iTool.ClusterComponent";

        /// <summary>
        /// 数据库名称，默认：[iTool.QueueStorage]；
        /// 如果数据库不存在会在运行时创建
        /// </summary>
        public string QueueDatabaseName { get; set; } = "iTool.QueueStorage";

        public string GetConnection(string tableName = null)
        {
            if (string.IsNullOrWhiteSpace(this.PWD))
            {
                return $"Data Source={this.DataSource};database={(tableName ?? this.DatabaseName)};Integrated Security=True;MultipleActiveResultSets=true;";
            }
            else
            {
                return $"Data Source={this.DataSource};database={(tableName ?? this.DatabaseName)};uid={this.UID};pwd={this.PWD};MultipleActiveResultSets=true;";
            }
        }
    }

}
